package cn.gxa.j229.bug.finance.controller.loanuser;

import cn.gxa.j229.bug.finance.pojo.PlatformFunds;
import cn.gxa.j229.bug.finance.service.loanuser.PlatformFundsService;
import cn.gxa.j229.bug.finance.utils.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: fenglin
 * @Date:2020/9/26 12:46
 * @Version 1.0
 */
@Controller
@RequestMapping("/platformFunds")
public class PlatformFundsController {

    @Autowired
    PlatformFundsService platformFundsService;

    JsonResult jsonResult = new JsonResult();

    @PostMapping("/selectAll")
    @ResponseBody
    public Map findAll(@RequestBody PlatformFunds platformFunds){

        Integer limit = platformFunds.getLimit();
        Integer page = platformFunds.getPage();
        List<Map<String, String>> select = platformFundsService.selectAll(page, limit);
        int count = platformFundsService.selectAllCount(page, limit);
        jsonResult.put("count",count);


        jsonResult.setData(select);
        jsonResult.setCode("200");
        jsonResult.setMsg("成功");
        return jsonResult.getValues();
    }
    @PostMapping("/selectSerialAndTypeAndIoaccount")
    @ResponseBody
    public Map selectSerialAndTypeAndIoaccount(@RequestBody PlatformFunds platformFunds){
        String serial = platformFunds.getSerial();
        Integer type = platformFunds.getType();
        Integer ioaccount = platformFunds.getIoaccount();
        Integer limit = platformFunds.getLimit();
        Integer page = platformFunds.getPage();
        if (ioaccount==0 || ioaccount.equals("")){
            List<Map<String, String>> selectSerialAndTypeAndIoaccount = platformFundsService.selectSerialAndTypeAndIoaccount(platformFunds);
            int count = platformFundsService.selectSerialAndTypeAndIoaccountCount(platformFunds);

            jsonResult.put("count",count);
            jsonResult.setData(selectSerialAndTypeAndIoaccount);
            jsonResult.setCode("200");
            jsonResult.setMsg("成功");
        }else  if (ioaccount==1){
            List<Map<String, String>> moneyrecord = platformFundsService.selectMoneyrecord(platformFunds);
            int count = platformFundsService.selectMoneyrecordCount(platformFunds);
            jsonResult.put("count",count);
            jsonResult.setData(moneyrecord);
            jsonResult.setCode("200");
            jsonResult.setMsg("成功");
        }else  if (ioaccount==2){
            List<Map<String, String>> rechargerecord = platformFundsService.selectRechargerecord(platformFunds);

            int count = platformFundsService.selectRechargerecordCount(platformFunds);
            jsonResult.put("count",count);
            jsonResult.setData(rechargerecord);
            jsonResult.setCode("200");
            jsonResult.setMsg("成功");
        }else {
            jsonResult.setCode("404");
            jsonResult.setMsg("网页走丢了");

        }




        return jsonResult.getValues();
    }
}
